/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.storage.api;

import com.jeesite.modules.storage.common.ServerResponse;
import com.jeesite.modules.storage.service.AddressService;
import com.jeesite.modules.storage.service.BankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 银行卡Controller
 */
@RestController(value = "apibank")
@RequestMapping(value = "/api/bank")
public class BankController extends APIController {

    @Autowired
    private BankService bankService;

    /**
     * 查询系统预设银行卡列表
     * @return 系统预设银行卡列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "sys/query")
    @ResponseBody
    public ServerResponse<List<String>> sysQuery()
    {
        return  ServerResponse.createBySuccess(200,bankService.getSysList());
    }

    /**
     * 查询银行卡类型列表
     * @return 银行卡类型列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "type/query")
    @ResponseBody
    public ServerResponse<List<String>> typeQuery()
    {
        return  ServerResponse.createBySuccess(200,bankService.getTypeList());
    }

    /**
     * 保存
     * @param memberId 会员Id
     * @param contact 联系人
     * @param number 卡号
     * @param name 名称
     * @param type 类型
     * @param phone 手机号
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "save")
    public ServerResponse<String> save(@RequestParam(value="memberId") String memberId,@RequestParam(value="contact") String contact,@RequestParam(value="number") String number,@RequestParam(value="name") String name,@RequestParam(value="type") String type,@RequestParam(value="phone") String phone)
    {
        Integer code = bankService.save(memberId,contact,number,name,type,phone);
        String msg = "";
        switch (code){
            case 200:
                msg = "更新成功";
                break;
            default:
                msg = "发生其它异常";
                break;
        }
        return  ServerResponse.createBySuccess(code,msg);
    }

    /**
     * 获取会员银行卡列表
     * @param memberId 会员Id
     * @param size 每页数量
     * @param page 页码
     * @return
     */
    @RequestMapping(method = RequestMethod.GET,value = "query")
    @ResponseBody
    public ServerResponse<List<Map>> query(@RequestParam(value="memberId") String memberId,@RequestParam(value="size",defaultValue = "5") Integer size, @RequestParam(value="page",defaultValue = "1") Integer page)
    {
        return  ServerResponse.createBySuccess(200,bankService.getListByMemberId(memberId,size,page));
    }
}
